package com.guigu.www.Service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.www.Service.StudentService;
import com.guigu.www.dao.ClassMapper;
import com.guigu.www.dao.StudentMapper;
import com.guigu.www.pojo.Class;
import com.guigu.www.pojo.PageVo;
import com.guigu.www.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper mapper;
    @Autowired
    private ClassMapper classMapper;
    @Override
    public PageVo<Student> pageStu(Map<String,String> map) {
        Student student = new Student();
        student.setSname(map.get("sname"));
        student.setSex(map.get("sex"));
        student.setCid(Integer.valueOf(map.get("cid")==null?"0":map.get("cid")));
        student.setBrit(map.get("brit"));
        student.setBri(map.get("bri"));
        PageHelper.startPage(
                Integer.parseInt(map.get("pageNum"))
                ,Integer.parseInt(map.get("pageSize"))
                        );
        List<Student> studentPage = mapper.findStudentPage(student);
        PageInfo<Student> pageInfo=new PageInfo<>(studentPage);
        long total = pageInfo.getTotal();
        List<Student> list = pageInfo.getList();
        return new PageVo<Student>(total,list);
    }

    @Override
    public void deleteByPrimaryKey(Integer sid) {
        mapper.deleteByPrimaryKey(sid);
    }

    @Override
    public void insert(Student record) {
        mapper.insert(record);
    }

    @Override
    public Student selectByPrimaryKey(Integer sid) {
        return mapper.selectByPrimaryKey(sid);
    }

    @Override
    public void updateByPrimaryKey(Student record) {
        mapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Class> findClass() {
        return classMapper.findClass();
    }
}
